/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.itlaobing.entity.DtoEntity;
import cn.itlaobing.util.IRowMapper;

/** 
 * ClassName: DtoDao <br/> 
 * Function:DtoDao<br/> 
 * date: 2017年11月1日 下午3:09:18 <br/> 
 * 
 * @author 王博 
 * @version  
 * @since JDK 1.8 
 */
public class DtoDao extends BaseDao<DtoEntity> {
	/** 
	 * queryAll:(全查). <br/>
	 * 
	 * @author 王博 
	 * @return
	 * @throws SQLException 
	 * @since JDK 1.8 
	 */  
	public List<DtoEntity> queryAll(int id) throws SQLException{
		String sql=
				"SELECT goods_id,order_number,user_id,amout,status_id,place_order,source_id,consignee,consignee_phone,consignee_address ,sourceid,source_name,id AS statusid ,statusname FROM (" + 
				"	SELECT t1.id AS goods_id ,order_number,user_id,place_order,amout,status_id,source_id,consignee,consignee_phone,consignee_address,t2.id AS sourceid,source_name " + 
				"		FROM tbl_goods t1 INNER JOIN tbl_source t2 ON t1.source_id=t2.id)s1 " + 
				"	INNER JOIN tbl_status s2 ON s1.status_id=s2.id and s1.user_id=?";
		List<DtoEntity> listDto=db.executeQuery(sql, new IRowMapper<DtoEntity>() {
			
			@Override
			public DtoEntity rowMapper(ResultSet rs) throws SQLException {
				DtoEntity dto=new DtoEntity();
				dto.getGoodsEntity().setAmout(rs.getFloat("amout"));
				dto.getGoodsEntity().setConsignee(rs.getString("consignee"));
				dto.getGoodsEntity().setConsigneeAddress(rs.getString("consignee_address"));
				dto.getGoodsEntity().setConsigneePhone(rs.getString("consignee_phone"));
				dto.getGoodsEntity().setId(rs.getInt("goods_id"));
				dto.getGoodsEntity().setOrderNumber(rs.getString("order_number"));
				dto.getGoodsEntity().setPlaceOrder(rs.getDate("place_order"));
				dto.getGoodsEntity().setSourceId(rs.getInt("source_id"));
				dto.getGoodsEntity().setStatusId(rs.getInt("status_id"));
				dto.getGoodsEntity().setUserId(rs.getInt("user_id"));
				dto.getSourceEntity().setId(rs.getInt("sourceid"));
				dto.getSourceEntity().setSourceName(rs.getString("source_name"));
				dto.getStatusEntity().setId(rs.getInt("statusid"));
				dto.getStatusEntity().setStatusName(rs.getString("statusname"));
				return dto;
			}
		},id);
		System.out.println(listDto.toString());
		return listDto;
	}
}
